package com.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.util.JdbcUtil;
@WebServlet("/WorstationAddServlet")
public class WorstationAddServlet extends HttpServlet{

	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		Integer wid =Integer.parseInt( request.getParameter("wid"));
		String wname = request.getParameter("wname");
		String waddress = request.getParameter("waddress");
		String wdesc = request.getParameter("wdesc");
		try{
		JdbcUtil jdbc = new JdbcUtil();
		String sql = "insert into workstation(wid,wname,waddress,wdesc) values(?,?,?,?)";
		Object[] params = new Object[]{wid,wname,waddress,wdesc};
		jdbc.updatePreparedStatement(sql, params);
		jdbc.close();
		request.setAttribute("params", params);		
		request.getRequestDispatcher("/WorkstationSelect?action=query").forward(request, response);
		}catch(Exception e){
			e.printStackTrace();
			request.setAttribute("mess", "新增失败，请稍后重试");
			request.getRequestDispatcher("inserterror.jsp").forward(request, response);
		}
		
		
		
	}
	

}

